package com.taxigang.server;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

import com.taxigang.shared.RouteInfo;
import com.taxigang.shared.TaxiCompanyInfo;

public class PartnerDAO {
	private EntityManager em;
	public PartnerDAO(EntityManager em){
		this.em = em;
	}

	public RouteInfo find(String partnerId) {
		long longId = 0;
		try{
			longId = Long.parseLong(partnerId);
		}catch (Exception ex){
			return null;
		}
		
		Partner partner = em.find(Partner.class, longId);
		RouteInfo partnerInfo = null;
		if (partner != null){
			partnerInfo =  partner.getInfo();
		}
		
		return partnerInfo;
	}

	public void create(RouteInfo partnerInfo) {
		EntityTransaction transaction = em.getTransaction();
		try{
			transaction.begin();
			Partner partner = new Partner();
			partner.setInfo(partnerInfo);
			em.persist(partner);
		} catch(Exception ex){
			ex.printStackTrace();
		} finally {
			transaction.commit();
		}
	}



}
